package com.llsydn.demo.animation1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.animation.*;
import android.widget.RelativeLayout;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title 欢迎界面
 * @description 请填写相关描述
 * @date 2018/10/10 10:25
 */
public class WelcomActivity extends Activity {

    private RelativeLayout rl_welcome_root;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                startActivity(new Intent(WelcomActivity.this, SetupGuideActivity.class));
                finish();
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //当前activity被销毁了，移除未处理的消息对象
        handler.removeMessages(1);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcom);
        rl_welcome_root = findViewById(R.id.rl_welcome_root);

        //显示动画
        showAnimation();

        //发送延迟3秒的消息
        handler.sendEmptyMessageDelayed(1, 3000);
    }

    /**
     * 显示动画
     * 旋转动画   RotateAnimation：0--->360 视图的中心占2s
     * 透明度动画 AlphaAnimation：0 --->1 2s
     * 缩放动画  ScaleAnimation：0--->1 视图的中心点2s
     */
    private void showAnimation() {
        RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(2000);

        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        alphaAnimation.setDuration(2000);

        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(2000);

        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(rotateAnimation);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(scaleAnimation);

        rl_welcome_root.startAnimation(animationSet);
    }
}
